package com.yuejie.music.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yuejie.music.manager.MusicScoreManager;
import com.yuejie.music.manager.impl.MusicScoreManagerImpl;

/**
 * @ClassName: MusicScoreAction
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author husongbo
 * @date 2012-7-2 下午05:44:15
 * 
 */

public class MusicScoreAction  extends HttpServlet  {

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -1401902946001862019L;


	protected void doGet(HttpServletRequest request, HttpServletResponse response)
	{
		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");
		
		String result = "";
		String id = request.getParameter("id");
		PrintWriter writer = null;
		try 
		{
			MusicScoreManager manager = new MusicScoreManagerImpl();
			writer = response.getWriter();
			result = manager.getMusicInfo(id);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			result = "异常";
		}
		
		writer.println("<result>" + result + "</result>");
    }

	protected void doPost(HttpServletRequest request, HttpServletResponse response) 
	{	
		response.setContentType("text/xml");
		response.setCharacterEncoding("UTF-8");
		
		String result = "";
		String id = request.getParameter("id");
		String scoreTemp = request.getParameter("score");
		PrintWriter writer = null;
		try 
		{
			MusicScoreManager manager = new MusicScoreManagerImpl();
			writer = response.getWriter();
			int score = Integer.valueOf(scoreTemp);
			result = manager.updateMusicScore(id, score);
		} 
		catch (Exception e) 
		{
			e.printStackTrace();
			result = "异常";
		}
		
		writer.println("<result>" + result + "</result>");
    }

}
